package cn.edu.njust.Filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(urlPatterns = {"/allCourse.jsp", "/hitCourse.jsp", "/CourseFailure.jsp", "/loginFailure.jsp", "/delCourse.jsp"})
public class ZFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        String uri = req.getRequestURI();
        String url = req.getContextPath();
        if(uri.equals(url+"/hitCourse.jsp")){
            request.getRequestDispatcher("CourseController?operation=hitC").forward(request,response);
        }
        else if(uri.equals(url+"/allCourse.jsp")){
            request.getRequestDispatcher("CourseController").forward(request,response);
        }
        else{
            response.getWriter().write("非法访问！");
        }
    }

    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }
}
